package com.sen.common.jquery;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

/**
 * tinytree的数据结构.
 * 
 * @author sen
 */
public class TinyTreeBean {

	private String id;
	private String name;
	private String url;
	private boolean leaf = true;
	private boolean checked;
	private boolean disabled;
	private boolean hide;
	
	private long childCount = 0L;
	private List<TinyTreeBean> children = new ArrayList<TinyTreeBean>();

	public TinyTreeBean() {
		// empty!
	}
	
	public TinyTreeBean(String id, String name) {
		this.id = id;
		this.name = name;
	}
	
	public boolean isHide() {
		return hide;
	}

	public void setHide(boolean hide) {
		this.hide = hide;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public boolean isLeaf() {
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	public List<TinyTreeBean> getChildren() {
		return children;
	}

	public void setChildren(List<TinyTreeBean> children) {
		this.children = children;
		if (CollectionUtils.isEmpty(children)) {
			setLeaf(true);
		} else {
			setLeaf(false);
			childCount += children.size();
		}
	}
	
	public void addChild(TinyTreeBean child) {
		children.add(child);
		setLeaf(false);
		childCount++;
	}

	public long getChildCount() {
		return childCount;
	}

	public void setChildCount(long childCount) {
		this.childCount = childCount;
		if (childCount > 0L) {
			setLeaf(false);
		} else {
			setLeaf(true);
		}
	}
}
